package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

public  class SessionUtil {
    public static final String USER_SUCCESS = "USER_SUCCESS";
    public static final String USER_MESSAGE = "USER_MESSAGE";


    public static HttpSession getSession() {
        ServletRequestAttributes attrs =  (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }

    public static void setUserSuccess(String userSuccess){
        userSuccess = SessionUtil.USER_SUCCESS;
    }

    public static String getUserSuccess() {
        return USER_SUCCESS;
    }

    public static void setUserMessage(String userMessage){
        userMessage = SessionUtil.USER_MESSAGE;
    }

    public static String getUserMessage() {
        return USER_MESSAGE;
    }

    public static Employee getEmployee(){
        Employee attribute = (Employee) getSession().getAttribute(SessionUtil.USER_SUCCESS);
        return attribute;
    }


}
